import java.util.Scanner;

public class test2 {
    public static void swap(Test tests[],int i,int j)//交换
    {
        Test tem= tests[j];
        tests[j]=tests[i];
        tests[i]=tem;
    }
    public static void Maopao(Test tests[],int n)//冒泡
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n-i;j++)
            {
                if(tests[j].sum<tests[j+1].sum)
                {
                    swap(tests,j,j+1);
                }
                else if(tests[j].sum==tests[j+1].sum)
                {
                    if(tests[j].computer<tests[j+1].computer)
                    {
                        swap(tests,j,j+1);
                    }
                    else if(tests[j].computer==tests[j+1].computer)
                    {
                        if(tests[j].english<tests[j+1].english)
                        {
                            swap(tests,j,j+1);
                        }
                    }
                }
            }
        }
    }
    public static void Xuanze(Test tests[],int n)//选择
    {
        int i,j;
        for(i=1;i<=n-1;i++)
        {
            int id=i;
            for(j=i+1;j<=n;j++)
            {
                if(tests[i].sum<tests[j+1].sum)
                {
                    id=j;
                }
                else if(tests[i].sum==tests[j+1].sum)
                {
                    if(tests[i].computer<tests[j+1].computer)
                    {
                        id=j;
                    }
                    else if(tests[i].computer==tests[j+1].computer)
                    {
                        if(tests[i].english<tests[j+1].english)
                        {
                            id=j;
                        }
                    }
                }
            }
            if(id!=i)
            {
                swap(tests,id,i);
            }
        }
    }
    public static void Charu(Test tests[],int n)//插入
    {
        int i,j;
        for(i=2;i<=n;i++)
        {
            Test key=tests[i];
            int tem=tests[i].sum;
            int tem1=tests[i].computer;
            int tem2=tests[i].english;
            for(j=i-1;j>=1;j--)
            {
                if(tem>tests[j].sum)
                {
                    tests[j+1]=tests[j];
                }
                else if(tem==tests[j].sum)
                {
                    if(tem1>tests[j].computer)
                    {
                        tests[j+1]=tests[j];
                    }
                    else if(tem1==tests[j].computer)
                    {
                        if(tem2>tests[j].english)
                        {
                            tests[j+1]=tests[j];
                        }
                        else {
                            break;
                        }
                    }
                    else {
                        break;
                    }
                }
                else {
                    break;
                }
            }
            tests[j+1]=key;
        }
    }
    public static void main(String[] args) {

        Scanner in=new Scanner(System.in);
        System.out.println("请输入人数：");
        int n=in.nextInt();
        Test[] tests=new Test[n+1];
        for(int i=1;i<=n;i++)
        {
            Test tests1 = new Test();
            System.out.println("请输入学号：");
            tests1.setId(in.next());

            System.out.println("请输入姓名：");
            tests1.setName(in.next());

            System.out.println("请输入计算机成绩：");
            tests1.setComputer(in.nextInt());

            System.out.println("请输入英语成绩：");
            tests1.setEnglish(in.nextInt());

            System.out.println("请输入数学成绩：");
            tests1.setMath(in.nextInt());
            tests1.sum=tests1.computer+tests1.english+tests1.math;
            tests[i]=tests1;
        }
        System.out.println("请选择排序算法");
        int ops= in.nextInt();
        switch (ops)
        {
            case 1:{
                Xuanze(tests,n);
                break;
            }
            case 2:{
                Maopao(tests,n);
                break;
            }
            case 3:{
                Charu(tests,n);
                break;
            }
        }
        for(int i=1;i<=n;i++)
        {
            System.out.println(" 姓名："+tests[i].name+" 学号:"+tests[i].id+" 总成绩："+tests[i].sum+" 计算机成绩："+tests[i].computer+" 英语成绩："+tests[i].english+" 数学成绩："+tests[i].math);
        }
    }
}
